home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2006 April / DPPRO0406DVD.ISO / Essentials / Programming / Eclipse SDK / eclipse-SDK-3.1.1-win32.exe / eclipse / plugins / org.apache.ant_1.6.5 / bin / envset.cmd < prev    next >
Encoding:
Text File  |  2005-09-29  |  3.9 KB  |  131 lines

  1. /*
  2.  
  3.     Copyright 2003-2004 The Apache Software Foundation
  4.   
  5.     Licensed under the Apache License, Version 2.0 (the "License");
  6.     you may not use this file except in compliance with the License.
  7.     You may obtain a copy of the License at
  8.   
  9.         http://www.apache.org/licenses/LICENSE-2.0
  10.   
  11.     Unless required by applicable law or agreed to in writing, software
  12.     distributed under the License is distributed on an "AS IS" BASIS,
  13.     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.     See the License for the specific language governing permissions and
  15.     limitations under the License.
  16.  
  17. SET environment variables
  18. First optional parameter:
  19.    ;     parameters are considered parts of a path variable, semicolons are
  20.          appended to each element if not already present
  21.    -D    parameters are properties for Java or Makefile etc., -D will be
  22.          prepended and the parameters will be separated by a space
  23.    =D    the same as above but equal sign is not required
  24.    ,     parameters should be comma separated in the environment variable
  25.    -     parameters should be separated by the next parameter
  26.    Other values mean that the first parameter is missing and the environment
  27.    variable will be set to the space separated parameters
  28.  
  29. Second parameter: name of the environment variable
  30.  
  31. Next parameters: values
  32. ; implies that the equal sign is considered a part of the parameter and is
  33. not interpreted
  34.  
  35. -D requires parameters in the form name=value. If the equal sign is not found,
  36. the parameters are changed to name=expanded_name
  37.  
  38. Other options have optional equal sign. If it is found, only the part after
  39. the equal sign will be oprionally expanded.
  40.  
  41. If the parameter is the minus sign, the next parameter will not be expanded.
  42. If the parameter is a single dot, it will be replaced with the value of the
  43. environment variable as it existed before envset was invoked.
  44.  
  45. For other parameters the batch looks for the environment variable with the
  46. same name (in uppercase). If it is found, it forms the expanded_name. If
  47. the environment variable with such a name does not exist, the expanded_name
  48. will hold the parameter name without case conversion.
  49. */
  50.  
  51. parse arg mode envar args
  52.  
  53. equal = 0
  54. sep = ' '
  55.  
  56. /* Parse command line parameters */
  57. select
  58.   when mode='-' then do
  59.     sep = envar
  60.     parse var args envar args
  61.   end
  62.   when mode=';' then do
  63.     sep = ''
  64.     equal = -1
  65.   end
  66.   when mode='-D' then equal = 1
  67.   when mode='=D' then mode = '-D'
  68.   when mode=',' then sep = ','
  69. otherwise
  70.   args = envar args
  71.   envar = mode
  72.   mode = ''
  73. end
  74.  
  75. env = 'OS2ENVIRONMENT'
  76. envar = translate(envar)
  77. orig = value(envar,,env)
  78. newval = ''
  79. expand = 1
  80.  
  81. /* for each parameter... */
  82. do i = 1 to words(args)
  83.   if expand > 0 & word(args, i) = '-' then expand = 0
  84.   else call addval word(args, i)
  85. end
  86.  
  87. /* Optionally enclose path variable by quotes */
  88. if mode = ';' & pos(' ', newval) > 0 then newval = '"' || newval || '"'
  89.  
  90. /* Set the new value, 'SET' cannot be used since it does not allow '=' */
  91. x = value(envar, newval, env)
  92. exit 0
  93.  
  94. addval: procedure expose sep equal orig expand newval mode env
  95. parse arg var
  96.  
  97. if var = '.' then expvar = orig
  98. else do
  99.   if equal >= 0 then do
  100.     parse var var name '=' val
  101.     if val = '' then var = name
  102.     else var = val
  103.   end
  104.   if expand = 0 then expvar = var
  105.   else expvar = value(translate(var),,env)
  106.   if expvar = '' then expvar = var
  107.   if equal >= 0 then do
  108.     if val = '' then do
  109.       parse var expvar key '=' val
  110.       if val <> '' then name = key
  111.       else do
  112.         if equal > 0 then val = key
  113.         else name = key
  114.       end
  115.     end
  116.     else val = expvar
  117.     if pos(' ', val) > 0 | pos('=', val) > 0 then val = '"' || val || '"'
  118.     if val = '' then expvar = name
  119.     else expvar = name || '=' || val
  120.   end
  121.   if mode = '-D' then expvar = '-D' || expvar
  122.   if mode = ';' then do
  123.     if right(expvar, 1) <> ';' then expvar = expvar || ';'
  124.   end
  125. end
  126.  
  127. if newval = '' then newval = expvar
  128. else newval = newval || sep || expvar
  129. expand = 1
  130. return
  131.